using System;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.IO;
using System.Text;
namespace time
{

    public class person3
    {
        public string name { get; set; }
        public string age { get; set; }
    }

    public class work_json
    {
        public static void Main()
        {
            person3 p1 = new person3() { name = "1", age = "1" };
            person3 p2 = new person3() { name = "2", age = "2" };
            string s = json(p1);
            Console.WriteLine(s);
            Console.Read();
        }

        public static string json<T>(T t)
        {
            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));
            MemoryStream ms = new MemoryStream();
            ser.WriteObject(ms, t);
            string jsonString = Encoding.UTF8.GetString(ms.ToArray());
            ms.Close();
            return jsonString;

        }
    }
}

